package mobi.yuanshen.service.impl;

import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vod.model.v20170321.CreateUploadVideoResponse;
import mobi.yuanshen.common.domain.dto.AliVodDTO;
import mobi.yuanshen.common.domain.dto.RequestUploadVideoDTO;
import mobi.yuanshen.common.utils.AliVODUtils;
import mobi.yuanshen.service.FileService;
import org.springframework.stereotype.Service;

@Service
public class FileServiceImpl implements FileService {
    @Override
    public AliVodDTO requestUploadVideo(RequestUploadVideoDTO uploadVideoDTO) {
        CreateUploadVideoResponse response;
        try {
            response = AliVODUtils.getCreateUploadVideoResponse(uploadVideoDTO.getVideoName(), uploadVideoDTO.getVideoTitle());
        } catch (ClientException e) {
            throw new RuntimeException(e);
        }
        return AliVodDTO
                .builder()
                .videoId(response.getVideoId()) // 视频ID
                .videoAddress(response.getUploadAddress()) // 视频上传地址
                .videoAuth(response.getUploadAuth()) // 视频上传凭证
                .build();
    }
}
